package com.jagochan.gateway.filters;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class LearnGlobalFilter implements GlobalFilter , Ordered {

    /**
     * @param exchange 请求上下文(包含整个过滤器链中的共享数据，如 request、response等)
     * @param chain    过滤器链（当前过滤器执行完后，要调用过滤器链中的下一个过滤器）
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        HttpHeaders headers = exchange.getRequest().getHeaders();
        System.out.println("headers = " + headers);

        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0; // 值越小，优先级越高
    }
}
